package com.itboye.textileexpres.order;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.textileexpes.beans.MyOrderBeans;
import com.itboye.textileexpres.R;
import com.itboye.textileexpres.util.XImageLoader;
import com.itboye.textileexptes.config.GlobalConfig;

public class ToBeHippedOrderAdapter extends BaseAdapter {
	Context context;
	MyOrderBeans beans;

	public ToBeHippedOrderAdapter(Context context, MyOrderBeans beans) {
		// TODO Auto-generated constructor stub
		this.context = context;
		this.beans = beans;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return Integer.valueOf(beans.getCount());
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		viewHolder holder = null;
		if (convertView == null) {
			holder = new viewHolder();
			LayoutInflater inflater = LayoutInflater.from(context);
			convertView = inflater.inflate(R.layout.item_order, null);
			holder.area_tv = (TextView) convertView.findViewById(R.id.area_tv);
			holder.state_tv = (TextView) convertView.findViewById(R.id.state_tv);
			holder.goods_name1_tv = (TextView) convertView.findViewById(R.id.goods_name1_tv);
			holder.goods_name2_tv = (TextView) convertView.findViewById(R.id.goods_name2_tv);
			holder.goods_detail_tv = (TextView) convertView.findViewById(R.id.goods_detail_tv);
			
			holder.color_tv = (TextView) convertView.findViewById(R.id.color_tv);
			holder.price_tv = (TextView) convertView.findViewById(R.id.price_tv);
			holder.num_tv = (TextView) convertView.findViewById(R.id.num_tv);
			holder.total_num_tv = (TextView) convertView.findViewById(R.id.total_num_tv);
			
			holder.total_price_tv = (TextView) convertView.findViewById(R.id.total_price_tv);
			holder.freight_tv = (TextView) convertView.findViewById(R.id.freight_tv);
			
			holder.goods_img=(ImageView) convertView.findViewById(R.id.goods_img);
			convertView.setTag(holder);
		} else {
			holder = (viewHolder) convertView.getTag();
		}
		
		holder.area_tv.setText(beans.getList().get(position).getNote());
		holder.state_tv.setText(beans.getList().get(position).getNote());
		/**
		 * 第二级
		 */
		int lenth=beans.getList().get(position).getItems().size();
		for (int i = 0; i < lenth; i++) {
			
			holder.goods_name1_tv.setText(beans.getList().get(position).getItems().get(i).getName());
			holder.goods_name2_tv.setText(beans.getList().get(position).getItems().get(i).getName());
			holder.goods_detail_tv.setText(beans.getList().get(position).getItems().get(i).getName());
			
			holder.color_tv.setText(beans.getList().get(position).getItems().get(i).getSku_desc());
			holder.price_tv.setText(beans.getList().get(position).getItems().get(i).getPrice());
			holder.num_tv.setText(beans.getList().get(position).getItems().get(i).getCount());
			
			holder.total_num_tv.setText("合计"+beans.getList().get(position).getItems().get(i).getWeight()+"米");
			holder.total_price_tv.setText("合计"+beans.getList().get(position).getItems().get(i).getOri_price()+"元");
			holder.goods_detail_tv.setText("(包含运费"+beans.getList().get(position).getItems().get(i).getWeight()+"元)");
			System.out.println(""+ beans.getList().get(position).getItems().get(i).getName());
			System.out.println("imgimg"+beans.getList().get(position).getItems().get(i).getImg());
			XImageLoader.load(GlobalConfig.IMAGE_DOUBLE+beans.getList().get(position).getItems().get(i).getImg(), holder.goods_img);
		}
//		
		return convertView;
	}

	class viewHolder {
		private TextView area_tv;
		private TextView state_tv;
		private TextView goods_name1_tv;
		private TextView goods_name2_tv;
		private TextView goods_detail_tv;
		
		private TextView color_tv;
		private TextView price_tv;
		private TextView num_tv;
		private TextView total_num_tv;//合计多少米
		private TextView total_price_tv;//合计多少元
		private TextView freight_tv;//包含运费
		
		private ImageView goods_img;

	}
}
